package emt.friendtracking;

import emt.friendtracking.maps.AnswerAccept;
import emt.friendtracking.maps.AnswerDecline;
import emt.friendtracking.maps.TrackingActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class NotificationActivity extends BaseActivity
{
	private TextView nameTextView;
	private Button acceptButton, declineButton;
	private static final String TAG = NotificationActivity.class.getSimpleName();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		Log.i(TAG, "onCreated."); //TODO "onCreated."
		
        setContentView(R.layout.notification_dialog);
        
        nameTextView = (TextView) findViewById(R.id.textViewNametoBeFound);
        acceptButton = (Button) findViewById(R.id.acceptButton);
        declineButton = (Button) findViewById(R.id.declineButton);
        
        Data data = new Data();
        Data.Information information = data.getItemById(BaseActivity.getIdOfNewRow());
        data.close();
        nameTextView.setText(information.getUserName());
        final String phoneNumber = information.getPhoneNumber();
        final double destLongitude = information.getLongitudeOther();
        final double destLatitude = information.getLatitudeOther();
        final double meLongitude = information.getLongitudeMe();
        final double meLatitude = information.getLatitudeMe();
        
        acceptButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v)
			{
				Log.i(TAG, "Request accepted. TrackingActivity is called.");
				MyApplication.getAppContext().startActivity(new Intent(MyApplication.getAppContext(), TrackingActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
				new AnswerAccept(BaseActivity.getUsername(), phoneNumber, destLongitude, destLatitude, meLongitude, meLatitude).start();
				finish();
			}
        });
        
        declineButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v)
			{
				Log.i(TAG, "Request declined. Activity is closed.");
				new AnswerDecline(BaseActivity.getUsername(), phoneNumber).start();
				finish();
			}
        });
	}
	
	@Override
	protected boolean isRouteDisplayed()
	{
		return false;
	}
}
